<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>弹窗实例</title>
    <link rel="stylesheet" href="__LIBS__/layui/css/layui.css"/>
    <link rel="stylesheet" href="__MODULE__/admin.css?v=318"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #formBasForm {
            max-width: 800px;
            margin: 30px 200px 50px;
        }

        .layui-form-item {
            display: flex;
        }

        .layui-form-label {
            flex: 3;
        }

        .layui-input-block {
            flex: 14;
        }

        .layui-input-block {
            margin-left: 20px !important;
            min-height: 36px;
        }

        .layui-upload-img {
            width: 200px;
            max-height: 120px;
            height: auto;
            margin: 0 10px 10px 0;
            cursor: pointer;
        }

        #formBasForm .layui-form-item {
            margin-bottom: 25px;
        }

        [lay-filter="eQuestionForm"] .layui-form-item, .layui-inline {
            margin-bottom: 0;
            margin-top: 20px;
        }

        .qa-xx-item {
            padding-left: 25px;
            margin-bottom: 20px;
        }

        .qa-xx-item-title {
            position: absolute;
            left: 0;
            line-height: 38px;
        }

    </style>
</head>
<body>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <ul class="layui-tab-title" style="margin-bottom: 20px;">
            <li class="layui-this"><a href="javascript:location.reload();">课程有效期设置</a></li>
        </ul>
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="eQuestionForm" style="max-width: 900px;">
                <input type="hidden" name="id" value="{$menuinfo['id']?$menuinfo['id']:''}">
                <div class="layui-form-item js-new-attr-list yxqset">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <div class="layui-form">
                            <table class="layui-table">
                                <colgroup>
                                    <col width="40%"/>
                                    <col width="40%"/>
                                    <col width="20%"/>
                                </colgroup>
                                <thead>
                                <tr>
                                    <th>选择有效期</th>
                                    <th>设置价格</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody class="ns-attr-new">

                                </tbody>
                            </table>
                        </div>
                        <button class="layui-btn" id="addField">添加有效期</button>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block text-center">
                        <button class="layui-btn" lay-filter="eQuestionSubmit" lay-submit>&emsp;提交&emsp;</button>
                        <button ew-event="closeThisTabs" type="button" class="layui-btn layui-btn-primary">&emsp;关闭&emsp;</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- js部分 -->
<script type="text/javascript" src="__LIBS__/layui/layui.js"></script>
<script type="text/javascript" src="__NJS__/common.js?v=317"></script>
<script src="__JS__/plugins/ueditor/ueditor.config.js"></script><!--百度富文本-->
<script src="__JS__/plugins/ueditor/ueditor.all.js"></script><!--百度富文本-->
<script>
        function deleteTr(obj) {
            //通过this找到父级元素节点
            var tr = obj.parentNode.parentNode;
            //找到表格
            var tbody = tr.parentNode;
            //删除行
            tbody.removeChild(tr);
            // layui.use('form', function(){ //此段代码必不可少
            //  var form = layui.form;
            //  form.render();
            // });
        }
    layui.use(['layer', 'form', 'xmSelect', 'cascader'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var xmSelect = layui.xmSelect;
        var cascader = layui.cascader;
        var admin = layui.admin;

        var num = 0;
        $("#addField").click(function(){
            
            console.log(num);
            var html =                                 
            "<tr>" +
                "<td>"+
                    '<select name="column[text' + num + '][yxqid]">'+
                        '{foreach name="yxqs" item="vo"}'+
                            '<option value="{$vo.id}">{$vo.name}</option>'+
                        '{/foreach}'+
                    '</select>'+
                "</td>"+
                "<td >"+
                '<input name="column[text' + num + '][price]" class="layui-input" placeholder="请输入价格" required lay-verify="required"/>'+
                "</td>"+
                "<td>"+
                '<a href="javascript:;" onclick="deleteTr(this)">'+
                '<i class="layui-icon layui-icon-close"></i>'+
                '</a>'+
                "</td>"+
            "</tr>";
            $(".ns-attr-new").append(html);
            num++;
            layui.use('form', function(){ //此段代码必不可少
             var form = layui.form;
             form.render();
            });
        })
        // 表单提交事件
        form.on('submit(eQuestionSubmit)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled', 'disabled');
            $.ajax({
                url: "{:url('yxq_set')}",
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, {icon: 1, time: 1500, shade: 0.1})
                        setTimeout(function () {
                            admin.closeThisTabs();
                        }, 1000);
                    } else {
                        $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                        wk.error(res.msg);
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>
</html>